#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        printf("Usage: %s filename\n", argv[0]);
        return 1;
    }
    FILE* pf = fopen(argv[1], "r");
    if(NULL == pf)
    {
        perror("fopen");
        return 1;
    }
    while(1)
    {
        char buffer[128];
        memset(buffer, 0, sizeof(buffer));
        int n = fread(buffer, sizeof(char), 127, pf);
        printf("%s", buffer);
        if(n < 127) 
        {
            if(feof(pf))
            {
                printf("到达文件末尾\n");
                break;
            }
            else if(ferror(pf))
            {
                printf("读取时发生错误\n");
                break;
            }
        }
    }
    
    return 0;
}
